package com.sddfp.common.utils;

import com.sddfp.common.constant.user.UserConstant;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class TokenUtils {
//    public static Long getTokenUserId() {
//        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
//        String token = request.getHeader("token");
//
//        token = token.replace("Bearer ","");
//        JwtTemplate jwtTemplate = new JwtTemplate();
//        Number userId = (Number) jwtTemplate.parseToken(token,"userId");
//        return userId.longValue();
//    }

    public static Long getTokenUserId() {
        HttpServletRequest request= ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String userId = request.getHeader(UserConstant.USERID);
        return Long.parseLong(userId);
    }
}
